# Content of picos.img:
# sector 0: boot sector (bootsect_asm.o)
# sector 1-16: kernel (kernel.img 15KB max)
# sector 17-2879: file system

#APPS=$(wildcard user/*.bin)
#FILES=$(wildcard *.txt)
fs_create=tools/fs_create
fs_add=tools/fs_add
fs_del=tools/fs_del
fs_list=tools/fs_list

admin=kernel/ident.txt
bin1=user/picoshell.bin
txt1=user/haha.txt
txt2=user/hehe.txt
txt3=user/hihi.txt
txt4=user/hoho.txt
txt5=user/huhu.txt
bin2=user/HEPIA.bin
bin3=user/compteur.bin


TOOLS=$(fs_create) $(fs_add) $(fs_del) $(fs_list)

all: build picos.img
	qemu-system-i386 -monitor stdio -hda picos.img

bochs: build picos.img
	bochs -f bochsrc

build:
	make -C boot
	make -C kernel
	make -C user
	make -C tools

picos.img: boot/bootsect_asm.o kernel/kernel.img picofs.img
	dd if=/dev/zero of=$@ bs=512 count=2880
	dd if=boot/bootsect_asm.o of=$@ bs=512 count=1 conv=notrunc
	dd if=kernel/kernel.img of=$@ bs=512 conv=notrunc seek=1
	dd if=picofs.img of=$@ bs=512 conv=notrunc seek=17

# 80 NO RIGHT #11 READ all # 1 READ USR # 44 Read all

picofs.img: $(TOOLS) $(admin) $(bin1) $(txt1) $(txt2) $(txt3) $(txt4) $(txt5) $(bin2) $(bin3)
	rm -f $@
	$(fs_create) $@
	$(fs_add) $@ 80 0 $(admin)
	$(fs_add) $@ 01 0 $(bin1)
	$(fs_add) $@ 44 1 $(txt1)   
	$(fs_add) $@ 40 2 $(txt2)
	$(fs_add) $@ 04 3 $(txt3)
	$(fs_add) $@ 44 2 $(txt4)
	$(fs_add) $@ 04 2 $(txt5)
	$(fs_add) $@ 11 1 $(bin2)
	$(fs_add) $@ 10 1 $(bin3)

	
clean:
	make -C boot $@
	make -C kernel $@
	make -C user $@
	make -C tools $@
	rm -f *.img *.o *~ *.bin

rebuild: clean all
